﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;

namespace NutriLeaf.Phone.Core.Tip
{
    public class TipCategory
    {
        static Model.NutriLeafDataContext context = Model.Context.GetContext();

        public static void SaveLocal(List<Model.TipCategory> categories)
        {
            context.TipCategories.InsertAllOnSubmit(categories);
            context.SubmitChanges();
        }

        public static List<Model.TipCategory> GetLocal()
        {
            return (from Model.TipCategory a in context.TipCategories
                    select a).ToList();
        }

        public static void DeleteAll()
        {
            context.TipCategories.DeleteAllOnSubmit(GetLocal());
            context.SubmitChanges();
        }

        public static Model.TipCategory Convert(TipService.TipCategory category)
        {
            Model.TipCategory cat = new Model.TipCategory();
            cat.CategoryDescription = category.CategoryDescription;
            cat.CategoryName = category.CategoryName;
            cat.ParentCategoryID = (int)category.ParentCategoryID;
            cat.TipCategoryID = category.TipCategoryID;
            return cat;
            
        }

        public static TipService.TipCategory Convert(Model.TipCategory category)
        {
            TipService.TipCategory cat = new TipService.TipCategory();
            cat.CategoryName = category.CategoryName;
            cat.CategoryDescription = category.CategoryDescription;
            cat.ParentCategoryID = category.ParentCategoryID;
            cat.TipCategoryID = category.TipCategoryID;
            return cat;

        }

        public static List<Model.TipCategory> Convert(List<TipService.TipCategory> categories)
        {
            List<Model.TipCategory> cats = new List<Model.TipCategory>();
            foreach (TipService.TipCategory category in categories)
            {
                cats.Add(Convert(category));
            }

            return cats;
        }

        public static List<TipService.TipCategory> Convert(List<Model.TipCategory> categories)
        {
            List<TipService.TipCategory> cats = new List<TipService.TipCategory>();
            foreach (Model.TipCategory category in categories)
            {
                cats.Add(Convert(category));
            }

            return cats;
        }


    }
}
